/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package automate;

import java.awt.Color;
import java.awt.Component;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author S219
 */
class ImageListener implements MouseListener {
    private JLabel image;
    private JPanel panel;
    private Diapositives diapo;
    
    public ImageListener(JLabel image, JPanel panel, Diapositives diapo) {
        this.image = image;
        this.panel = panel;
        this.diapo = diapo;
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        Component[] labels;
        //si doucle clic on lance le diapo
        if(e.getClickCount() == 2){
            try {
                diapo.MettreEnRoute();
            } catch (IOException ex) {
                Logger.getLogger(ImageListener.class.getName()).log(Level.SEVERE, null, ex);
            }
            diapo.setEtat(2);
        }
        else{
            switch(diapo.getEtat()){
            case 0 : //premiere image sélectionnée
                //on réinitialiser les bordures de tout les composants
                labels = this.panel.getComponents();
                for (Component l : labels) {
                    ((JLabel)l).setBorder(BorderFactory.createEmptyBorder());
                }
                this.image.setBorder(BorderFactory.createLineBorder(Color.yellow,3));
                diapo.setImage_selectionnee(this.image);
                diapo.setEtat(1);
                break;
            case 1 :
                //on réinitialiser les bordures de tout les composants
                labels = this.panel.getComponents();
                for (Component l : labels) {
                    ((JLabel)l).setBorder(BorderFactory.createEmptyBorder());
                }
                this.image.setBorder(BorderFactory.createLineBorder(Color.yellow,3));
                diapo.setImage_selectionnee(this.image);
                break;       
        }
        }
        System.out.println(""+e.getComponent().getName());
        
        
    }

    @Override
    public void mousePressed(MouseEvent e) {
        
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        //System.out.println("champ de vision");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        //System.out.println("Hors du champ de vision");
    }
    
    
}
